//
//  RBCompExpZsCollectionCell.m
//  RMMaterialRed
//
//  Created by XBWH on 2024/3/13.
//

#import "RBCompExpZsCollectionCell.h"

@interface RBCompExpZsCollectionCell ()
@property(strong,nonatomic)UIView *bgView;
@property(strong,nonatomic)UILabel *topLabel;
@property(strong,nonatomic)UILabel *bottomLabel;
@end

@implementation RBCompExpZsCollectionCell
-(instancetype)initWithFrame:(CGRect)frame{
   if(self = [super initWithFrame:frame]){
       
       self.backgroundColor = [UIColor whiteColor];
       self.contentView.backgroundColor = [UIColor whiteColor];
       [self rb_initViewUI];
       [self setNeedsLayout];
       
   }
   return self;
}
-(void)rb_initViewUI{
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.topLabel];
    [self.bgView addSubview:self.bottomLabel];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.height.mas_equalTo(RBScaleWidth(30));
    }];
    [self.bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topLabel.mas_bottom);
        make.left.bottom.right.mas_equalTo(0);
    }];
}
-(void)setSelectModel:(RBSelectMethodsModel *)selectModel{
    _selectModel=selectModel;
    self.topLabel.text = selectModel.itemName;
    self.topLabel.text = [self.topLabel.text stringByReplacingOccurrencesOfString:@"j" withString:@""];
    self.topLabel.text = [self.topLabel.text stringByReplacingOccurrencesOfString:@"7" withString:@"7+"];
    
    if ([_expModel.forecastType isEqualToString:@"jq"]) {
        self.topLabel.text = [NSString stringWithFormat:@"%@球",self.topLabel.text];
    }
    
    self.bottomLabel.text = [NSString stringWithFormat:@"%@",selectModel.odds];
    
    if (selectModel.recommend == 1) {
        self.topLabel.textColor = [UIColor whiteColor];
        self.bottomLabel.textColor = [UIColor whiteColor];
    }else{
        self.topLabel.textColor = RBColor(153, 153, 153);
        self.bottomLabel.textColor = RBColor(51, 51, 51);
    }
    
    //指数
    if (_expModel.zs == 0) {
        self.bgView.layer.cornerRadius = 0;
        self.bgView.layer.borderWidth = 0.5;
        self.bgView.layer.borderColor = [UIColor whiteColor].CGColor;
        self.topLabel.textColor = RBColor(153, 153, 153);
        self.bottomLabel.textColor = RBColor(51, 51, 51);

        NSString *selectStr = @"";
        // 由于为空的时候，也会出现数组为1的情况
        if (_indexPath.item < self.forecastResultArray.count>0 && self.forecastResultArray.count>1) {
            if ([_expModel.forecastType isEqualToString:@"rqspf"]) {
                selectStr = self.forecastResultArray[_indexPath.item+1];
            } else if ([_expModel.forecastType isEqualToString:@"rfsf"]) {//让分胜负，交换主胜和客胜位置
                if (_indexPath.item>0 && [self.forecastResultArray[_indexPath.item] isEqualToString:@"1"]) {
                    selectStr = @"0";
                } else if(_indexPath.item>0 && [self.forecastResultArray[_indexPath.item] isEqualToString:@"0"]){
                    selectStr = @"1";
                }
            }else{
                selectStr = self.forecastResultArray[_indexPath.item];
            }
        }
        
        if ([selectStr intValue] == 1) { //如果是专家推荐的
            self.topLabel.textColor = [UIColor whiteColor];
            self.bottomLabel.textColor = [UIColor whiteColor];
            self.backgroundColor = [UIColor whiteColor];
        }else{// 不是专家推荐的，平台返回的效果展示
            // 0 负 1平 3胜   大小球/大小分：数值与盘口相比，rqsf当为平1 时比赛结束显示 走水
            if ([selectModel.articleFinish intValue] == 1) { // 结束的料才展示结果
                if ([_expModel.forecastType isEqualToString:@"spf"] || [_expModel.forecastType isEqualToString:@"rqspf"]||[_expModel.forecastType isEqualToString:@"rqsf"]||[_expModel.forecastType isEqualToString:@"rfsf"]) {
                    if(selectModel.matchResult.length == 0){ // 如果是结果异常的情况下
                        selectModel.matchResult = @"100000";
                    }
                }
                if ([_expModel.forecastType isEqualToString:@"jq"]) {  // 如果是进球数,已经结束，没有中
                }
                if ([_expModel.forecastType isEqualToString:@"dxf"] || [_expModel.forecastType isEqualToString:@"dxq"]){
                    NSArray *zsArr = [_expModel.midZS componentsSeparatedByString:@","];
                    NSString *oddsStr;
                    if ([_expModel.forecastType isEqualToString:@"dxf"]) {
                        oddsStr = zsArr[0];
                    }else if ([_expModel.forecastType isEqualToString:@"dxq"]){
                        oddsStr = zsArr[1];
                    }
                }
            }
        }
    }else{//指数不是0
    }
    
    if ([self.bottomLabel.text containsString:@"主"]) {
        self.bottomLabel.textColor = RBColor(242, 48, 48);
        NSMutableAttributedString *hintString =[[NSMutableAttributedString alloc]initWithString:self.bottomLabel.text];
            //获取要调整颜色的文字位置
        NSRange range =[[hintString string]rangeOfString:[NSString stringWithFormat:@"%@",@"主"]];
            [hintString addAttribute:NSForegroundColorAttributeName value:RBColor(51, 51, 51) range:range];
        self.bottomLabel.attributedText = hintString;
    }
    
    if ([self.bottomLabel.text containsString:@"客"]) {
        self.bottomLabel.textColor = RBColor(242, 48, 48);
        NSMutableAttributedString *hintString =[[NSMutableAttributedString alloc]initWithString:self.bottomLabel.text];
            //获取要调整颜色的文字位置
        NSRange range =[[hintString string]rangeOfString:[NSString stringWithFormat:@"%@",@"客"]];
            [hintString addAttribute:NSForegroundColorAttributeName value:RBColor(51, 51, 51) range:range];
        self.bottomLabel.attributedText = hintString;
    }

    if ([_expModel.forecastType isEqualToString:@"rqsf"]||[_expModel.forecastType isEqualToString:@"rfsf"]) {
        if ([self.topLabel.text containsString:@"主负"]) {
            self.topLabel.text = @"客胜";
        }
    }
}
-(void)setSelected:(BOOL)selected{
    if (self.isDisPlay) {  // 是否是纯展示
        return;
    }
}
- (UIView *)bgView{
    if(_bgView==nil){
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}
-(UILabel *)topLabel{
    if(_topLabel==nil){
        _topLabel = [UILabel rb_labelWithTitle:@"让胜" color:RBColor(153, 153, 153) font:RBPingFangFont(12) alignment:NSTextAlignmentCenter];
        _topLabel.backgroundColor = RBColor(245, 245, 245);
    }
    return _topLabel;
}
-(UILabel *)bottomLabel{
    if(_bottomLabel==nil){
        _bottomLabel = [UILabel rb_labelWithTitle:@"5.45" color:RBColor(51, 51, 51) font:RBPingFangFont(12) alignment:NSTextAlignmentCenter];
    }
    return _bottomLabel;
}

@end
